package api

import (
	"blizzard/app/model"
	"blizzard/app/service"
	"blizzard/app/utils/code"
	"blizzard/app/utils/response"
	"github.com/gogf/gf/net/ghttp"
)

var Admin = new(apiAdmin)

type apiAdmin struct {}

func (a *apiAdmin) Login(r *ghttp.Request) {
	var (
		data *model.AdminLoginParam
	)
	if err := r.Parse(&data); err != nil {
		response.JsonExit(r, code.ParamError, err.Error())
	}
	if err := service.Admin.Login(r, data); err != nil {
		response.JsonExit(r, code.AccountError, err.Error())
	}
	response.Json(r, code.Success, code.SuccessMsg)
}

func (a *apiAdmin) Logout(r *ghttp.Request) {
	var (
		data *model.AdminLoginParam
		err error
	)
	if err = r.Parse(&data); err != nil {
		response.JsonExit(r, code.ParamError, err.Error())
	}
	if err = service.Admin.Logout(r, data); err != nil {
		response.JsonExit(r, code.AccountError, err.Error())
	}
	response.Json(r, code.Success, code.SuccessMsg)
}